@extends('layouts.default')
@section('css')
<link rel="stylesheet" href="{{asset('admin-lte/plugins/datatables/dataTables.bootstrap4.css')}}">
{{--<link rel="stylesheet" href="{{asset('admin-lte/dist/css/font-awesome4.4.0.css')}}">--}}
{{--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">--}}
{{--<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">--}}
@stop

@section('content')
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">酒店管理 / <a class="text-primary" href="{{url('admin/hotel/index')}}">酒店列表</a></h3>
                </div>

                <div class="card-body">
                    @include('layouts.message')
                    <button class="btn btn-info btn-sm" style="margin-bottom:10px" onclick="location.href='{{url('admin/hotel/create_view')}}'">添加酒店</button>
                    <button data-href="{{url('admin/hotel/apply_template')}}" class="btn btn-primary btn-sm batch-template" style="margin-bottom:10px" >批量应用模板</button>
                    <table id="example1" class="table table-bordered table-striped">
                        <thead>
                        <tr>
                            <th><input type="checkbox" class="selAll"></th>
                            <th>操作</th>
                            <th>酒店名称</th>
                            <th>分成比例</th>
                            <th>联系人</th>
                            <th>手机号</th>
                            <th>详细地址</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($list as $v)
                            <tr>
                                <td><input type="checkbox" value="{{$v['hotel_id']}}" name="hotel_id" class="sel-spu"></td>

                                <td>
                                    <a href="{{url('admin/machine/index',['hotel_id'=>$v['hotel_id']])}}" class="btn btn-sm btn-info">设备列表</a>
                                    <button class="btn btn-sm btn-success" onclick="location.href='{{url('admin/hotel/hotel_goods_view',['hotel_id'=>$v['hotel_id']])}}'">商品列表</button>
                                    <button class="btn btn-sm btn-primary" onclick="location.href='{{url('admin/hotel/edit_view',['hotel_id'=>$v['hotel_id']])}}'">编辑</button>
                                    <button class="btn btn-sm btn-danger del-goods" data-href="{{url('admin/hotel/delete_hotel',['hotel_id'=>$v['hotel_id']])}}">删除</button>
                                </td>
                                <td>{{$v['name']}}</td>
                                <td>{{$v['divide_rate']}}</td>
                                <td>{{$v['concact_user']}}</td>
                                <td>{{$v['phone']}}</td>
                                <td>{{$v['address']}}</td>
                            </tr>
                        @endforeach
                        </tbody>
                        <tfoot>
                        <tr>
                            <td colspan="5" style="text-align: center">
                                {{$pages}}
                            </td>
                        </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>
@stop
@section('script')
    <script src="{{asset('admin-lte/plugins/datatables/jquery.dataTables.js')}}"></script>
    <script src="{{asset('admin-lte/plugins/datatables/dataTables.bootstrap4.js')}}"></script>
    {{--layer插件--}}
    <script src="{{asset("admin-lte/plugins/layer-v3.1.1/layer.js")}}" type="text/javascript"></script>
    <script>
        var edit_url = '{{$edit_url}}',
            del_url = '{{$del_url}}';
        $('#example1').on('click','.del-goods',function(e){
            layer.confirm('确认要删除该酒店吗？',function(){
                location.href = $(e.target).data('href');
            })
        })
            .on('click','.edit-goods',function(e){
                location.href = $(e.target).data('url');
            });

        //批量上下架操作
        $('.batch-template').on('click',function(e){
            var target = $(e.target),
                url = target.data('href'),
                sel_spu_id = [];
            $.each($('input[name="hotel_id"]:checked'),function(k,v){
                sel_spu_id.push($(v).val());
            });

            if(sel_spu_id.length === 0){
                layer.alert('请至少选择一个酒店');
                return false;
            }
            layer.confirm('你确定要应用模板于选中的酒店吗?',function(){
                sel_spu_id = sel_spu_id.join(',');
                location.href = url + '/' + sel_spu_id;
                // location.href = url + '/' + sel_spu_id + '/' + marketable;
            })

        });

        //全选反选
        $('.selAll').click(function(e){
            $.each($('tbody input[type="checkbox"]'),function(k,v){
                $(v).prop('checked',$(e.target).prop('checked'));
            })
        })

    </script>
@stop